<!DOCTYPE html>
<html>
<head>
    <title>Circuit Diagram Fig. 3.26</title>
</head>
<body>
<canvas id="circuitCanvas" width="450" height="400" style="border:1px solid #000;"></canvas>
<script>
    const canvas = document.getElementById('circuitCanvas');
    const ctx = canvas.getContext('2d');

    // --- Style and Font ---
    ctx.lineWidth = 2;
    ctx.strokeStyle = 'black';
    ctx.fillStyle = 'black';
    ctx.font = 'bold 18px serif';
    ctx.textAlign = 'left';
    ctx.textBaseline = 'middle';

    // --- Coordinates ---
    const xLeft = 80;
    const xSwitchPivot = 150;
    const xMid = 210;
    const xInductorStart = xSwitchPivot + 20;
    const xInductorEnd = 330;
    const xRight = 380;

    const yTop = 80;
    const yGround = 320;
    
    // --- Draw Wires ---
    ctx.beginPath();
    // Ground line
    ctx.moveTo(xLeft, yGround);
    ctx.lineTo(xRight, yGround);
    // Right vertical wire
    ctx.moveTo(xRight, yTop);
    ctx.lineTo(xRight, yGround);
    // Top wire (inductor part)
    ctx.moveTo(xInductorEnd, yTop);
    ctx.lineTo(xRight, yTop);
    // Wire from switch to inductor
    ctx.moveTo(xSwitchPivot, yTop);
    ctx.lineTo(xInductorStart, yTop);
    // Left branch wires
    ctx.moveTo(xLeft, yTop);
    ctx.lineTo(xLeft, 110); // From A to Resistor
    ctx.moveTo(xLeft, 190); // From Resistor to Battery
    ctx.lineTo(xLeft, 230);
    ctx.moveTo(xLeft, 270); // From Battery to Ground
    ctx.lineTo(xLeft, yGround);
    // Middle branch wires
    ctx.moveTo(xMid, yTop);
    ctx.lineTo(xMid, 120); // From B to Resistor
    ctx.moveTo(xMid, 280); // From Resistor to Ground
    ctx.lineTo(xMid, yGround);
    ctx.stroke();

    // --- Draw Components ---
    
    // Battery (1V)
    ctx.beginPath();
    ctx.moveTo(xLeft - 15, 230);
    ctx.lineTo(xLeft + 15, 230); // Positive terminal
    ctx.moveTo(xLeft - 8, 270);
    ctx.lineTo(xLeft + 8, 270); // Negative terminal
    ctx.stroke();
    ctx.fillText('1V', xLeft + 25, 250);

    // Resistor (1 Ohm)
    ctx.beginPath();
    const r1_x = xLeft;
    const r1_y_start = 110;
    const r1_len = 80;
    const r1_w = 10;
    ctx.moveTo(r1_x, r1_y_start);
    ctx.lineTo(r1_x + r1_w, r1_y_start + r1_len * 1/8);
    ctx.lineTo(r1_x - r1_w, r1_y_start + r1_len * 3/8);
    ctx.lineTo(r1_x + r1_w, r1_y_start + r1_len * 5/8);
    ctx.lineTo(r1_x - r1_w, r1_y_start + r1_len * 7/8);
    ctx.lineTo(r1_x, r1_y_start + r1_len);
    ctx.stroke();
    ctx.fillText('1 \u03A9', r1_x + 20, r1_y_start + r1_len / 2);

    // Resistor R
    ctx.beginPath();
    const rR_x = xMid;
    const rR_y_start = 120;
    const rR_len = 160;
    const rR_w = 10;
    ctx.moveTo(rR_x, rR_y_start);
    ctx.lineTo(rR_x + rR_w, rR_y_start + rR_len * 1/8);
    ctx.lineTo(rR_x - rR_w, rR_y_start + rR_len * 3/8);
    ctx.lineTo(rR_x + rR_w, rR_y_start + rR_len * 5/8);
    ctx.lineTo(rR_x - rR_w, rR_y_start + rR_len * 7/8);
    ctx.lineTo(rR_x, rR_y_start + rR_len);
    ctx.stroke();
    ctx.fillText('R = 10\u2074 \u03A9', rR_x + 20, rR_y_start + rR_len / 2);

    // Inductor L
    const l_x_start = xInductorStart;
    const l_y = yTop;
    const num_coils = 4;
    const coil_len = (xInductorEnd - xInductorStart) / num_coils;
    ctx.beginPath();
    for (let i = 0; i < num_coils; i++) {
        ctx.arc(l_x_start + (i + 0.5) * coil_len, l_y, coil_len / 2, Math.PI, 2 * Math.PI);
    }
    ctx.stroke();
    ctx.fillText('L = 1H', l_x_start + 20, l_y - 25);

    // Switch S
    // Contacts
    ctx.beginPath();
    ctx.arc(xLeft, yTop, 4, 0, 2 * Math.PI); // Contact A
    ctx.fill();
    ctx.beginPath();
    ctx.arc(xMid, yTop, 4, 0, 2 * Math.PI); // Contact B
    ctx.fill();
    // Arm
    ctx.beginPath();
    ctx.moveTo(xSwitchPivot, yTop);
    ctx.lineTo(xLeft, yTop);
    ctx.stroke();
    ctx.fillText('S', xSwitchPivot - 8, yTop - 25);
    ctx.fillText('A', xLeft - 25, yTop + 5);
    ctx.fillText('B', xMid + 10, yTop + 5);

    // Ground Symbol
    ctx.beginPath();
    ctx.moveTo(xMid - 20, yGround);
    ctx.lineTo(xMid + 20, yGround);
    ctx.moveTo(xMid - 12, yGround + 8);
    ctx.lineTo(xMid + 12, yGround + 8);
    ctx.moveTo(xMid - 6, yGround + 16);
    ctx.lineTo(xMid + 6, yGround + 16);
    ctx.stroke();

    // Current Arrow
    const arrow_cx = (xMid + xRight) / 2;
    const arrow_cy = (yTop + yGround) / 2;
    const arrow_r = 70;
    const arrow_start_angle = -0.4 * Math.PI;
    const arrow_end_angle = 1.4 * Math.PI;

    ctx.beginPath();
    ctx.arc(arrow_cx, arrow_cy, arrow_r, arrow_start_angle, arrow_end_angle);
    ctx.stroke();
    
    // Arrowhead
    const head_len = 12;
    const head_angle = Math.PI / 6; // Angle of arrowhead lines relative to the tangent
    const x_end = arrow_cx + arrow_r * Math.cos(arrow_end_angle);
    const y_end = arrow_cy + arrow_r * Math.sin(arrow_end_angle);
    const tangent_angle = arrow_end_angle + Math.PI / 2;
    
    const x1 = x_end - head_len * Math.cos(tangent_angle - head_angle);
    const y1 = y_end - head_len * Math.sin(tangent_angle - head_angle);
    const x2 = x_end - head_len * Math.cos(tangent_angle + head_angle);
    const y2 = y_end - head_len * Math.sin(tangent_angle + head_angle);
    
    ctx.beginPath();
    ctx.moveTo(x_end, y_end);
    ctx.lineTo(x1, y1);
    ctx.moveTo(x_end, y_end);
    ctx.lineTo(x2, y2);
    ctx.stroke();


    // --- Caption ---
    ctx.font = '18px serif';
    ctx.textAlign = 'center';
    ctx.fillText('Fig. 3.26', canvas.width / 2, yGround + 50);

</script>
</body>
</html>